home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6832 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.0 KB

  1. Path: crchh327.rich.bnr.ca!jobell
  2. From: jobell@bnr.ca (Bret Bieghler)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Diff between const str& and const str*
  5. Date: 19 Feb 1996 22:01:46 GMT
  6. Organization: Bell-Northern Research Ltd.
  7. Message-ID: <4gas0a$rj0@crchh327.rich.bnr.ca>
  8. References: <4g93d4$ej4@newsstand.cit.cornell.edu>
  9. NNTP-Posting-Host: crchh524.rich.bnr.ca
  10.  
  11. In article <4g93d4$ej4@newsstand.cit.cornell.edu>,
  12. Warren Ouyang <wo10@cornell.edu> wrote:
  13. >Hello all, I was wondering... in C++, is there a difference between 
  14. >"const str&" and "const str*" as function parameters?  (str is a class).  
  15. >Thanks for any help!
  16. >
  17. >Warren
  18.  
  19. One is a reference, the other a pointer.
  20.  
  21. void foobar (const int& x, const int* y)
  22. {
  23.     cout << x << endl;    // equivalent to cout << *y << endl;
  24.     cout << y << endl;
  25. }
  26.  
  27. void main (void)
  28. {
  29.     int a = 5;
  30.  
  31.     foobar (a, &a);
  32. }
  33.  
  34. gives
  35.  
  36. 5
  37. 0xabcdabcd (some address)
  38.  
  39. JB
  40.  
  41. -- 
  42. Joseph A. Bell (NOT Bret Bieghler) jobell@bnr.ca
  43. Northern Telecom / Bell-Northern Research
  44. "What?  Evacuate now, in our moment of triumph?  Surely you overestimate their chances."
  45.